package com.ss.android.article.browser.view.user;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.a.a.e;
import com.a.a.s;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.database.BrowserHistory;
import com.ss.android.article.browser.database.b.HistoryManager;
import com.ss.android.common.app.AbsFragment;

import java.util.ArrayList;
import java.util.List;

public final class o extends AbsFragment implements u {
    final class a extends Adapter {
        private final LayoutInflater a;
        private final o b;

        public a(o arg2, Context arg3) {
            this.b = arg2;
            this.a = LayoutInflater.from(arg3);
        }

        public final int getItemCount() {
            return o.c(this.b).size();
        }

        public final void onBindViewHolder(ViewHolder arg7, int arg8) {
            boolean v0_2;
            com.ss.android.article.browser.view.user.x.a v0_1;
            com.ss.android.article.browser.view.user.x.a v1;
            boolean v3 = false;
            boolean v2 = true;
            Object v0 = o.c(this.b).get(arg8);
            com.ss.android.article.browser.view.user.o.o$b.a(((o$b) arg7)).setText(((BrowserHistory) v0).title);
            o$b.b(((o$b) arg7)).setTag(v0);
            o$b.b(((o$b) arg7)).setOnClickListener(o.e(this.b));
            if (((o$b) arg7).itemView.getTag() == null) {
                v1 = new com.ss.android.article.browser.view.user.x.a();
            } else {
                v1 = (x.a) ((o$b) arg7).itemView.getTag();
            }

            if (o.c(this.b).size() <= 1) {
                v1.a = true;
                v0_1 = v1;
                v0_1.b = v2;
            } else if (arg8 == 0) {
                v1.a = true;
                v0_2 = !android.support.design.a.isTextEquals(o.c(this.b).get(arg8).readableTime, o.c(this.b).get(arg8 + 1).readableTime) ? true : false;
                v1.b = v0_2;
            } else {
                if (arg8 == o.c(this.b).size() - 1) {
                    if (!android.support.design.a.isTextEquals(o.c(this.b).get(arg8).readableTime, o.c(this.b).get(arg8 - 1).readableTime)) {
                        v3 = true;
                    }

                    v1.a = v3;
                    v0_1 = v1;
                } else {
                    v0_2 = !android.support.design.a.isTextEquals(o.c(this.b).get(arg8).readableTime, o.c(this.b).get(arg8 - 1).readableTime) ? true : false;
                    v1.a = v0_2;
                    if (!android.support.design.a.isTextEquals(o.c(this.b).get(arg8).readableTime, o.c(this.b).get(arg8 + 1).readableTime)) {
                        v0_1 = v1;
                    } else {
                        v2 = false;
                        v0_1 = v1;
                    }
                }
                v0_1.b = v2;
            }

            ((o$b) arg7).itemView.setTag(v1);
        }

        public final ViewHolder onCreateViewHolder(ViewGroup arg3, int arg4) {
            return new o$b(this.a, arg3);
        }
    }

    static final class o$b extends ViewHolder {
        private View a;
        private TextView b;

        public o$b(LayoutInflater arg5, ViewGroup arg6) {
            super(arg5.inflate(com.ss.android.article.browser.R.layout.j0, arg6, false));
            UIUtils.setVisibility(this.itemView.findViewById(com.ss.android.article.browser.R.id.divider), 8);
            UIUtils.setVisibility(this.itemView.findViewById(com.ss.android.article.browser.R.id.ac2), 8);
            this.b = this.itemView.findViewById(com.ss.android.article.browser.R.id.title);
            this.a = this.itemView.findViewById(com.ss.android.article.browser.R.id.ac3);
            ViewGroup.LayoutParams v0 = this.b.getLayoutParams();
            ((ViewGroup.MarginLayoutParams) v0).leftMargin += UIUtils.px2dp(arg5.getContext(), 4f);
            v0 = this.a.getLayoutParams();
            ((ViewGroup.MarginLayoutParams) v0).rightMargin += UIUtils.px2dp(arg5.getContext(), 5f);
        }

        static TextView a(o$b arg1) {
            return arg1.b;
        }

        static View b(o$b arg1) {
            return arg1.a;
        }
    }

    HistoryManager a;
    private View b;
    private RecyclerView c;
    private Adapter d;
    private List<BrowserHistory> e;
    private View.OnClickListener f;
    private x g;
    private View h;
    private v i;

    public o() {
        this.e = new ArrayList();
        this.f = new p(this);
    }

    static View a(o arg1) {
        return arg1.b;
    }

    static void a(o arg3, boolean arg4) {
        boolean v1 = false;
        View v2 = arg3.h;
        int v0 = arg4 ? 0 : 8;
        UIUtils.setVisibility(v2, v0);
        if (arg3.i != null) {
            v v0_1 = arg3.i;
            if (!arg4) {
                v1 = true;
            }

            v0_1.b(v1);
        }
    }

    static View b(o arg1) {
        return arg1.h;
    }

    static List<BrowserHistory> c(o arg1) {
        return arg1.e;
    }

    static Adapter d(o arg1) {
        return arg1.d;
    }

    static View.OnClickListener e(o arg1) {
        return arg1.f;
    }

    public final void f() {
        if (this.i != null) {
            v v1 = this.i;
            boolean v0 = this.h.getVisibility() != View.VISIBLE ? true : false;
            v1.b(v0);
        }
    }

    public final void onActivityCreated(@Nullable Bundle arg3) {
        super.onActivityCreated(arg3);
        s v0 = this.a.d();
        ((e) v0).b = android.support.design.a.c();
        ((e) v0).c = android.support.design.a.b();
        v0.a(new r(this));
    }

    public final void onAttach(Context arg2) {
        super.onAttach(arg2);
        if ((arg2 instanceof v)) {
            this.i = ((v) arg2);
        }
    }

    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.a = HistoryManager.getInstance();
    }

    @Nullable
    public final View onCreateView(LayoutInflater arg4, @Nullable ViewGroup arg5, @Nullable Bundle arg6) {
        this.b = arg4.inflate(com.ss.android.article.browser.R.layout.dv, arg5, false);
        this.c = this.b.findViewById(com.ss.android.article.browser.R.id.recycler_view);
        this.h = this.b.findViewById(com.ss.android.article.browser.R.id.s9);
        this.b.getViewTreeObserver().addOnPreDrawListener(new q(this));
        UIUtils.setVisibility(this.b.findViewById(com.ss.android.article.browser.R.id.divider), 0);
        ((TextView) this.b.findViewById(com.ss.android.article.browser.R.id.s_)).setText(com.ss.android.article.browser.R.string.jl);
        this.c.setLayoutManager(new LinearLayoutManager(this.getContext()));
        this.g = new x(this.getContext());
        this.g.a = this.e;
        this.c.addItemDecoration(this.g);
        this.d = new a(this, this.getContext());
        this.c.setAdapter(this.d);
        return this.b;
    }

    public final void onDetach() {
        super.onDetach();
        this.i = null;
    }
}

